//
//  JXHCustomPresentationController.swift
//  JXHSinaWeiBo
//
//  Created by juxiaohui on 16/10/18.
//  Copyright © 2016年 juxiaohui. All rights reserved.
//

import UIKit

class JXHCustomPresentationController: UIPresentationController {
    
    var presentFrame = CGRect.init()
    
    
    lazy var coverView = UIView()
    

    //自定义UIPresentationController改变转场尺寸

    //modal是把控制的view加载containerView做动画
    
    override func containerViewWillLayoutSubviews() {
        super.containerViewWillLayoutSubviews()
        
        presentedView?.frame = presentFrame
        //添加蒙版
        setupCoverView()
    }
}

// MARK: - UI相关
extension JXHCustomPresentationController {

    func setupCoverView()  {
        
        containerView?.insertSubview(coverView, at: 0)
        coverView.backgroundColor = UIColor.black.withAlphaComponent(0.5)
        coverView.frame = containerView!.bounds
        //添加手势
        
        let tap = UITapGestureRecognizer.init(target: self, action: #selector(JXHCustomPresentationController.coverViewClick))
        coverView.addGestureRecognizer(tap)
    }
}
// MARK: - 事件监听
extension JXHCustomPresentationController {

    func coverViewClick() {
        presentedViewController.dismiss(animated: true, completion: nil)
    }
}

